package com.sudo.boot.channel;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Demo3 {

    /**
     * FileChannel 写数据
     */
    public static void main(String[] args) throws IOException {
        RandomAccessFile src = new RandomAccessFile("D:\\code-space\\java\\io-demo\\src\\main\\resources\\src.txt", "rw");
        FileChannel srcChannel = src.getChannel();
        RandomAccessFile dest = new RandomAccessFile("D:\\code-space\\java\\io-demo\\src\\main\\resources\\dest.txt", "rw");
        FileChannel destChannel = dest.getChannel();

//        srcChannel.transferTo(0, srcChannel.size(), destChannel);
        destChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        destChannel.close();
    }
}
